package com.candy.candycommon.utils;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Configuration;

/**
 * @author suYanLong
 * @date 2022年10月13日 11:48
 */
@Slf4j
@Configuration
public class ApplicationContentUtils implements ApplicationContextAware, DisposableBean {

    public static ApplicationContext applicationContext;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        log.info("加载成功。。。。。");
        this.applicationContext = applicationContext;
    }

    public static ApplicationContext getApplicationContext() {
        return applicationContext;
    }

    public static <T> T getBean(Class<T> var1) {
        return getApplicationContext().getBean(var1);
    }

    @Override
    public void destroy() throws Exception {
        log.error("destroy ....");
    }

}
